package com.hazardSoft.eStore.entities;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Transient;

import com.hazardSoft.eStore.utils.QueryConstants;

@Entity
@NamedQueries({
	@NamedQuery(name = QueryConstants.QUERY_LIST_CATEGORIES, query = "FROM Category c ORDER BY c.name ASC")
})
public class Category implements Serializable, Cloneable {
	@Id
	private int id;

	@Lob
	private String name;

//	@OneToMany(mappedBy="category")
	@Transient
	private Collection<Product> productCollection;

	private static final long serialVersionUID = 1L;

	public Category() {
		super();
	}
	
	public Category(int id) {
		this.id = id;
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Collection<Product> getProductCollection() {
		return this.productCollection;
	}

	public void setProductCollection(Collection<Product> productCollection) {
		this.productCollection = productCollection;
	}
	
	public String toString(){
		StringBuffer categoryString = new StringBuffer();
		
		categoryString.append("id: ["+this.getId()+"] " );
		categoryString.append("name: ["+this.getName()+"] ");

		return categoryString.toString();
	}
	
	public Object clone(){
		Category cloneCategory = new Category();
		
		cloneCategory.setId(this.getId());
		cloneCategory.setName(this.getName());
	
		return cloneCategory;
	}
	
	public boolean equals(Object object){
		if (object == null) {
			return false;
		}
		if (!(object instanceof Category)) {
			return false;
		}
		
		Category category = (Category) object;
		
		if (category.getName() == null) {
			return false;
		} else {
			if (!(category.getName().equals(this.getName()))) {
				return false;
			}
		}
		return true;
	}

}
